#define _CRT_SECURE_NO_WARNINGS
int BTTreeHeight(struct TreeNode* root)
{
    if (root == NULL)
        return 0;
    int leftdepth = BTTreeHeight(root->left);
    int rightdepth = BTTreeHeight(root->right);
    return leftdepth > rightdepth ? leftdepth + 1 : rightdepth + 1;
}
bool isBalanced(struct TreeNode* root) {
    if (root == NULL)
        return true;
    int leftdepth = BTTreeHeight(root->left);
    int rightdepth = BTTreeHeight(root->right);
    if (abs(leftdepth - rightdepth) > 1)
        return false;
    return isBalanced(root->left) && isBalanced(root->right);
}